<html> <head>
<TITLE>The Linux Counter City Competition</TITLE>
</head>
<?php

  function urlify($name) {
     $country = strtoupper(substr($name, 0, 2));
     $rest = strtolower(substr($name, 2));
     return urlencode($country . $rest);
  }	
?>

  
<body bgcolor=white>
<h1><img src="/gifs/Logo-small.png">The City Competition</h1>
<?php
 $link = mysql_pconnect("", "counter", "password");
 mysql_select_db("counter");
?>
At <span id="gmtime">
<?php echo gmstrftime ("%b %d %Y %H:%M:%S",time())."\n"; ?>
 GMT, the following cities/states/countries are in the lead:<br>
<table border>
<tr><th>#<th>Name<th>Type<th>Population<th>Users<th>Density

<?php
 $query = mysql_query("select p.longname, p.type, p.population, p.users, p.users/p.population as density, p.name, pp.longname, ppp.longname as ppplongname 
 from places as p, places as pp left join places as ppp on (pp.within = ppp.f_key) where p.population <> '' and p.users > 5 and p.within = pp.f_key order by density desc limit 100");
$index = 0;
 while ($arr = mysql_fetch_row($query)) {
    $index += 1;
    $recname = $arr[5];
    $url = "/bycountry/" . urlify($recname) . ".html";
    echo "<tr>";
    echo "<td>" . $index . "<td>";
    echo "<a href=\"" . $url . "\">";
    if ($arr[1] == 'country') {
	echo $arr[0];
    } elseif ( $arr[7] == 'The World' || $arr[7] == 'NULL') {
	echo $arr[0] . ", " . $arr[6];
    } else {
	echo $arr[0] . ", " . $arr[6] . ", " . $arr[7] ;
    }
    echo "</a>";
    echo "<td>" . $arr[1]
	 . "<td align=\"right\">" . number_format( $arr[2] * 1000000, 0, ".", " ")
	 . "<td align=\"right\">" . $arr[3]
	 .  "<td align=\"right\">" . number_format($arr[4], 2) . "\n";
 }
 ?>
</table>
</body>
</html>
